R.version.string
library(repr)
library(ggplot2)
library(DT)
library(formattable)
library(plotly)
library(osmar)
library(maptools)
library(ggmap)
library(igraph)
library(leaflet)
library(networkD3)
library(RColorBrewer)
library(highcharter)
library(visNetwork)
library(d3heatmap)
ip <- as.data.frame(installed.packages()[,c(1,3:4)])
rownames(ip) <- NULL
ip <- ip[is.na(ip$Priority),1:2,drop=FALSE]
datatable(ip)
gc01 <- geocode("GUM Moscow", output = "more")
datatable(t(data.frame(gc01)))
formattable(data.frame(mapdist("GUM Moscow", "Bolshoy Theater")))
src <- osmsource_api()
bigbox <- center_bbox(38.6533, 55.7758, 3000, 3000)
bpavposad <- get_osm(bigbox, source = src)
str(bpavposad)
users <- sort(unique(bpavposad$nodes$attrs$user))
print(head(users, 12))
n <- replicate(20, rnorm(20))
n_data = data.frame(n)
A <- matrix(
c(0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),
nrow = 15,
ncol = 15,
byrow = TRUE)
pp_gmap <- get_map(location=c(lon = 38.6533, lat = 55.7758),
source = "google", maptype = "hybrid", zoom = 15)
ggmap(pp_gmap, extent = "normal")
var_ways <- route('GUM Moscow', 'Bolshoy Theater', alternatives = TRUE)
t(head(data.frame(var_ways)))
options(repr.plot.width=6, repr.plot.height=4)
map1 <- ggplot(data = var_ways) + coord_map() +
geom_leg(aes(x = startLon, xend = endLon, y = startLat, yend = endLat, color = route))
map1
options(repr.plot.width=14, repr.plot.height=5)
qmap(location=c(37.6150, 55.7610), zoom = 13, maptype = 'roadmap',
base_layer = ggplot(aes(x = startLon, y = startLat), data = var_ways)) +
geom_leg(aes(x = startLon, xend = endLon,
y = startLat, yend = endLat, color = route),
alpha = 0.5, size = 2, data = var_ways) +
labs(x = 'Longitude', y = 'Latitude', colour = 'Route') +
facet_wrap(~ route, ncol = 3) + theme(legend.position = 'top')
options(repr.plot.width=10, repr.plot.height=10)
plot(bpavposad)
ts <- find(bpavposad, node(tags(v == "traffic_signals")))
ts_pp <- subset(bpavposad, node_ids = ts)
bs <- find(bpavposad, node(tags(v %agrep% "busstop")))
bs_pp <- subset(bpavposad, node_ids = bs)
hw <- find(bpavposad, way(tags(k == "highway")))
hw <- find_down(bpavposad, way(hw))
hw_pp <- subset(bpavposad, ids = hw)
tu <- find(bpavposad, way(tags(k == "tunnel")))
tu <- find_down(bpavposad, way(tu))
tu_pp <- subset(bpavposad, ids = tu)
options(repr.plot.width=14, repr.plot.height=14)
plot_ways(hw_pp, col = "steelblue")
plot_ways(tu_pp, add = TRUE, col = "magenta")
plot_nodes(ts_pp, add = TRUE, col = "red")
plot_nodes(bs_pp, add = TRUE, col = "blue")
bg <- find(bpavposad, way(tags(k == "building")))
bg <- find_down(bpavposad, way(bg))
bg_pp <- subset(bpavposad, ids = bg)
bg_poly <- as_sp(bg_pp, "polygons")
spplot(bg_poly, col.regions=brewer.pal(12, "Set3"), c("version"))
bs_points <- as_sp(bs_pp, "points")
hw_line <- as_sp(hw_pp, "lines")
plot(bg_poly, col = "lightsteelblue")
plot(hw_line, add = TRUE, col = "blue")
plot(bs_points, add = TRUE, col = "red")
pl1 <- plot_ly(n_data, x=n_data[1:20,1], y=n_data[1:20,2], z=n_data[1:20,3], color = n_data[1:20,4],
text = paste("random variable: ", n_data[1:20,4]),
colors = 'Spectral', type="scatter3d", mode="markers",
marker = list(size = 10, symbol = "diamond-open"))
pl2 <- layout(pl1, title = "Random Matrix",
scene = list(xaxis = list(title = "var1"), yaxis = list(title = "var2"), zaxis = list(title = "var3")))
pl2
x <- rnorm(200)
y <- rchisq(200, df = 1, ncp = 0)
group <- sample(LETTERS[1:5], size = 200, replace = T)
size <- sample(1:5, size = 200, replace = T)
ds <- data.frame(x, y, group, size)
pl3 <- plot_ly(ds, type = "scatter", x = x, y = y, mode = "markers",
color=group, size = size, opacity=0.7, colors = 'PuRd')
pl4 <- layout(pl3, title = "Scatter Plot")
pl4
g <- graph_from_adjacency_matrix(A, mode = "undirected")
options(repr.plot.width=14, repr.plot.height=7)
plot(g, layout=layout_with_fr,
vertex.label.dist=1.5, vertex.label.color='black',
vertex.size=10, vertex.shape='csquare', vertex.color='steelblue',
edge.color='darkblue', edge.arrow.size=2.5)
shortest_paths(g, 4, 12)
options(repr.plot.width=14, repr.plot.height=7)
g1 <- sample_gnp(60, 1/50)
comps <- components(g1)$membership
colbar <- rainbow(max(comps)+1)
V(g1)$color <- colbar[comps+1]
plot(g1, layout=layout_with_fr, vertex.size=4,
vertex.label.dist=0.7, vertex.label.color='black')
nodes <- data.frame(id = 1:6, title = paste("node", 1:6),
shape = c("dot", "square"),
size = 10:15, color = c("blue", "red"))
edges <- data.frame(from = 1:5, to = c(5, 4, 6, 3, 3))
visNetwork(nodes, edges) %>%
visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)